package com.tiancheng.trade.settlement.controller.admin;

import com.tiancheng.trade.commom.core.data.Result;
import com.tiancheng.trade.settlement.bo.SSettleLettersDetailQueryBO;
import com.tiancheng.trade.settlement.model.settlement.SSettleLettersDetail;
import com.tiancheng.trade.settlement.service.settlement.ISSettleLettersDetailService;
import com.tiancheng.trade.settlement.vo.settlement.admin.SSettleLettersDetailQueryVo;
import com.tiancheng.trade.settlement.vo.settlement.admin.SettleLetterAdjustVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import java.util.List;

/**
 * 对账函
 *
 * @author likailun
 */
@RestController
@RequestMapping("/admin/settleLettersDetail")
@Validated
@Slf4j
public class SSettleLettersDetailAdminController {
    @Resource
    private ISSettleLettersDetailService settleLettersService;

    @PostMapping
    public Result queryLit(@Valid @RequestBody SSettleLettersDetailQueryVo settleLettersDetailQueryVo){
        return Result.success(settleLettersService.queryLit(SSettleLettersDetailQueryBO.build(settleLettersDetailQueryVo)));
    }

    /**
     * 根据对账编号查询商户对账函明细
     * @param code
     * @return
     */
    @GetMapping("/byParentSettleLetter/{code}")
    public Result queryLit(@PathVariable("code") String code){
        List<SSettleLettersDetail> list =settleLettersService.queryByParentSettleLetter(code);
        return Result.success(list);
    }

    /**
     * 根据商户对账函编号查询商户对账函明细
     * @param code
     * @return
     */
    @GetMapping("/queryAdjustBySubSettleLettersCode/{code}")
    public Result queryAdjustBySubSettleLettersCode(@PathVariable("code") String code){
        SSettleLettersDetail detail = settleLettersService.queryAdjustBySubSettleLettersCode(code);
        return Result.success(detail);
    }

    /**
     * 提交手动调整单
     * @param settleLetterAdjustVo
     * @return
     */
    @PostMapping("/adjust")
    public Result adjust(@RequestBody @Valid SettleLetterAdjustVo settleLetterAdjustVo){
        settleLettersService.adjust(settleLetterAdjustVo);
        return Result.success();
    }

    /**
     * 提交手动调整单
     * @param detail
     * @return
     */
    @PostMapping("/uploadAdjustByOriginalLettersCode")
    public Result uploadAdjust(@RequestBody @Valid SSettleLettersDetail detail){
        settleLettersService.uploadAdjust(detail);
        return Result.success();
    }

    /**
     * 导出手动调整的对账明细文件
     * @param settleLettersDetailQueryVo
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @PostMapping("/export")
    public Result export(@Valid @RequestBody SSettleLettersDetailQueryVo settleLettersDetailQueryVo, HttpServletRequest request, HttpServletResponse response) throws Exception {
        settleLettersService.export(settleLettersDetailQueryVo,request,response);
        return Result.success();
    }
}
